<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 * $Id: 2017-12-13 03:39:35 apple $
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'get';
$return=array();
$return['stmp_xuanxiang']=array (
  1 => '网易邮箱服务器（建议使用）',
  2 => 'qq邮箱服务器',
  3 => '126邮箱服务器',
);

if($_RQ['op']=='get'){
	$value=uni_setting('email');
	$return['item']=$value?$value:array();
	$htmls=array(
		'type'=>'edit',
		'post'=>'post',
		'desc'=>'邮件参数',
		'tabs'=>array(
			'0'=>array('op'=>'get','title'=>'邮件参数设置'),
		),
		'edit'=>array(
			array('type'=>'radio','title'=>'STMP服务器','name'=>'type', 'options'=>'stmp_xuanxiang' ),
			array('type'=>'string','title'=>'发送帐号','name'=>'username','help'=>'注意，请填写完整的邮箱账号。例如：xxx@163.com'),
			array('type'=>'string','title'=>'smtp客户端授权密码','name'=>'password' ),
			array('type'=>'string','title'=>'发件人名称','name'=>'sender','help'=>'填写名字或昵称'),
			array('type'=>'text','title'=>'邮件签名','name'=>'signature','help'=>'签名会自动追加到邮件内容的尾部'),
			array('type'=>'switch','title'=>'是否发送测试邮件','name'=>'test'),
			array('type'=>'string','title'=>'邮件地址','name'=>'to','show'=>array('test'=>1)),
			array('type'=>'string','title'=>'邮件标题','name'=>'title','show'=>array('test'=>1)),
			array('type'=>'text','title'=>'发送内容','name'=>'message','show'=>array('test'=>1)),
		)
	);
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='post'){
	$postdata=get_postdata();
	$fields=array('type','username','password','sender','signature');
	$setting=array_fields($fields,$postdata);
	uni_setting('email',$setting);
	if($postdata['test']){
		//发送测试邮件
		$res=cfc('http')->ihttp_email($postdata['to'],$postdata['title'],$postdata['message']);
		if(is_error($res)){
			exi('测试邮件发送失败！'.$res['message'],'error');
		}
	}
	exi('设置成功！');
}